from flask import Flask, redirect, url_for
from BookWorldWeb.config import DevConfig

from BookWorldWeb.models import db
from BookWorldWeb.extensions import bcrypt
from BookWorldWeb.controllers.blog import blog_blueprint


def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(DevConfig)

    # 初始化数据库
    db.init_app(app)
    # 初始化哈希算法(用于加密用户密码)
    bcrypt.init_app(app)

    @app.route('/')
    def index():
        return redirect(url_for('blog.home'))

    app.register_blueprint(blog_blueprint)

    return app
